package com.geeker.module.sys.user.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.geeker.common.xss.Xss;
import com.geeker.module.sys.role.domain.SysRole;
import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
import lombok.Data;

import java.util.Date;
import java.util.List;

@Data
@Schema(description = "用户实体")
public class SysUser {

    @Id
    private Long userId;

    private Long deptId;

    @Xss(message = "用户账号不能包含脚本字符")
    @NotBlank(message = "用户账号不能为空")
    @Size(min = 0, max = 30, message = "用户账号长度不能超过30个字符")
    @Schema(description = "登录账号")
    private String userName;

    @NotBlank(message = "用户账号不能为空")
    @Size(min = 0, max = 30, message = "用户账号长度不能超过30个字符")
    @Schema(description = "用户昵称")
    private String nickName;

    @Schema(description = "身份证号码")
    private String idCard;

    @Schema(description = "用户邮箱")
    private String email;

    @Schema(description = "手机号码")
    private String phone;

    @Schema(description = "性别")
    private Integer sex;

    @Schema(description = "头像路径")
    private String avatar;

    @JsonIgnore
    private String password;

    @Schema(description = "状态")
    private Integer status;

    @Column(isLogicDelete = true)
    private Integer deleteFlag;

    private String createBy;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    private String updateBy;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date updateTime;

    @Schema(description = "备注")
    private String remark;

    @Column(ignore = true)
    @Schema(description = "角色对象")
    private List<SysRole> roles;

    public boolean isAdmin() {
        return isAdmin(this.userId);
    }

    public static boolean isAdmin(Long userId) {
        return userId != null && 1L == userId;
    }
}
